import request from '../index'
import type {
  IAccount,
  IDataType,
  ILoginResult,
  IUserInfoResult,
  IUserMenu
} from './type'

enum LoginApi {
  AccountLogin = '/login',
  UserInfo = '/users/', // /user/:id
  UserMenus = '/role/' // role/:id/menu
}

export function accountLoginRequest(account: IAccount) {
  return request.post<IDataType<ILoginResult>>({
    url: LoginApi.AccountLogin,
    data: account
  })
}

export function requestUserInfoById(id: number) {
  return request.get<IDataType<IUserInfoResult>>({
    url: LoginApi.UserInfo + id,
    showLoading: false
  })
}

export function requestUserMenusByRoleId(roleId: number) {
  return request.get<IDataType<IUserMenu[]>>({
    url: LoginApi.UserMenus + roleId + '/menu',
    showLoading: false
  })
}
